package com.docmanage.web.controller.am;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import com.docmanage.am.api.RemoteApiClient;
import com.docmanage.am.domain.dto.AmDescriptionSearchDTO;
import com.docmanage.am.domain.dto.ParaApiDto;
import com.docmanage.am.domain.vo.AmDescriptionSearchVo;
import com.docmanage.am.domain.vo.GtserverApiVo;
import com.docmanage.am.service.impl.AmDescriptionService;
import com.docmanage.common.utils.SecurityUtils;
import org.apache.ibatis.annotations.Param;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.docmanage.common.annotation.Log;
import com.docmanage.common.core.controller.BaseController;
import com.docmanage.common.core.domain.AjaxResult;
import com.docmanage.common.enums.BusinessType;
import com.docmanage.am.domain.AmDescription;
import com.docmanage.common.utils.poi.ExcelUtil;
import com.docmanage.common.core.page.TableDataInfo;

/**
 * 档案著录Controller
 * 
 * @author docmanage
 * @date 2023-11-28
 */
@RestController
@RequestMapping("/am/description")
public class AmDescriptionController extends BaseController
{
    @Resource
    private AmDescriptionService amDescriptionService;

    @Resource
    private RemoteApiClient remoteApiClient;

    /**
     * 查询档案著录列表
     */
    @PreAuthorize("@ss.hasPermi('am:description:list')")
    @GetMapping("/list")
    public TableDataInfo list(AmDescriptionSearchDTO dto)
    {
        startPage();
        List<AmDescriptionSearchVo> list = amDescriptionService.selectAmDescriptionList(dto);
        return getDataTable(list);
    }

    /**
     * 查询档案著录列表数据对接获取数据
     */
//    @PreAuthorize("@ss.hasPermi('am:description:list')")
    @GetMapping("/apiList")
    public TableDataInfo apiList(ParaApiDto dto)
    {
        startPage();
        List<GtserverApiVo> list = remoteApiClient.getApiVO(dto);
        return getDataTable(list);
    }

    /**
     * 档案查询
     */
    @PreAuthorize("@ss.hasPermi('am:description:personList')")
    @GetMapping("/personList")
    public TableDataInfo personList(AmDescriptionSearchDTO dto)
    {
        startPage();
        List<AmDescriptionSearchVo> list = amDescriptionService.getPersonAmDescriptionList(dto);
        return getDataTable(list);
    }

    /**
     * 导出档案著录列表
     */
    @PreAuthorize("@ss.hasPermi('am:description:export')")
    @Log(title = "档案著录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AmDescriptionSearchDTO dto)
    {
        List<AmDescriptionSearchVo> list = amDescriptionService.selectAmDescriptionList(dto);
        ExcelUtil<AmDescriptionSearchVo> util = new ExcelUtil<>(AmDescriptionSearchVo.class);
        util.exportExcel(response, list, "档案著录数据");
    }

    /**
     * 获取档案著录详细信息
     */
    @PreAuthorize("@ss.hasPermi('am:description:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id, @Param("roleId") Long roleId)
    {
        return success(amDescriptionService.selectAmDescriptionById(id, roleId));
    }

    /**
     * 新增档案著录
     */
    @PreAuthorize("@ss.hasPermi('am:description:add')")
    @Log(title = "档案著录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AmDescription amDescription)
    {
        return toAjax(amDescriptionService.insertAmDescription(amDescription));
    }

    /**
     * 修改档案著录
     */
    @PreAuthorize("@ss.hasPermi('am:description:edit')")
    @Log(title = "档案著录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AmDescription amDescription)
    {
        return toAjax(amDescriptionService.updateAmDescription(amDescription));
    }

    /**
     * 删除档案著录
     */
    @PreAuthorize("@ss.hasPermi('am:description:remove')")
    @Log(title = "档案著录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(amDescriptionService.deleteAmDescriptionByIds(ids));
    }
}
